﻿using BLL;
using Entity;
using log4net;
using Microsoft.AspNetCore.Mvc;
using static System.Net.Mime.MediaTypeNames;
using System.Security.Cryptography;
using Tools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection.Emit;
using System.IO;
using System.Net.Mime;
using Microsoft.AspNetCore.StaticFiles;

namespace YunProject.Controllers
{
    public class ServicesController : Controller
    {
        public ILog log = LogManager.GetLogger(typeof(ServicesController));
        ReturnResult rsl;
        BarBLL barBLL;

        private readonly IWebHostEnvironment _webHostEnvironment;
        public ServicesController(IWebHostEnvironment webHostEnvironment)
        {
            barBLL = new BarBLL();
            _webHostEnvironment = webHostEnvironment;
        }
        [HttpPost]
        public JsonResult SaveBarCode()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("SaveBarCode参数：" + json);
                    rsl = barBLL.SaveBarcodes(json);
                    log.Info("SaveBarCode程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("SaveBarCode异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult GetPlanPrintBars()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetPlanPrintBars参数：" + json);
                    rsl = barBLL.GetPlanPrintBars(json);
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPlanPrintBars异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult FinishPlan()
        {
            rsl = new ReturnResult();
            try
            {
                PlanBLL planBLL = new PlanBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("FinishPlan参数：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = planBLL.FinishPlanGx(obj["plCode"].ToString(), obj["gxCode"].ToString(), obj["userCode"].ToString());
                    log.Info("FinishPlan程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPlanPrintBars异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult GetPrintGYData()
        {
            rsl = new ReturnResult();
            try
            {
                PlanBLL planBLL = new PlanBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetPrintGYData参数：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = planBLL.GetPrintGYData(json);
                    log.Info("GetPrintGYData程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPrintGYData异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }


        [HttpPost]
        public JsonResult GetPlanGxBarCodes()
        {
            rsl = new ReturnResult();
            try
            {
                PlanBLL planBLL = new PlanBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetPlanGxBarCodes参数：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = barBLL.GetPlanGxBarCodes(obj["plCode"].ToString(), obj["gxCode"].ToString(), obj["spec"].ToString());
                    log.Info("GetPlanGxBarCodes程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPlanGxBarCodes异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        [HttpPost]
        public JsonResult FenQieList()
        {
            rsl = new ReturnResult();
            try
            {
                PlanBLL planBLL = new PlanBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("FenQieList参数：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = planBLL.FenQieList(obj["plCode"].ToString(), obj["gxCode"].ToString());
                    log.Info("FenQieList程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("FenQieList异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        [HttpPost]
        public JsonResult SearchInventories()
        {
            rsl = new ReturnResult();
            try
            {
                InventoryBLL invBLL = new InventoryBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取参数";
                    return Json(rsl);
                }
                else
                {
                    log.Info("SearchInventories参数：" + json);
                    rsl = invBLL.SearchInventories(json);
                    log.Info("SearchInventories参数：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("SearchInventories异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        [HttpPost]
        public JsonResult SearchVendors()
        {
            rsl = new ReturnResult();
            try
            {
                CustomBLL cu = new CustomBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取参数";
                    return Json(rsl);
                }
                else
                {
                    log.Info("SearchVendors：" + json);
                    rsl = cu.SearchVendors(json);
                    log.Info("SearchVendors：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("SearchVendors异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        [HttpPost]
        public JsonResult SearchUsers()
        {
            rsl = new ReturnResult();
            try
            {
                InventoryBLL invBLL = new InventoryBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取参数";
                    return Json(rsl);
                }
                else
                {
                    log.Info("SearchUsers参数：" + json);
                    rsl = invBLL.SearchUsers(json);
                    log.Info("SearchUsers参数：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("SearchUsers异常：" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 获取U8采购入库单打码列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetPrintedBarcodes_ByRdrecord01_cCode_iRowNo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("PurchaseInPrint参数：" + json);
                    rsl.Data = barBLL.GetPrintedBarcodes_ByRdrecord01_cCode_iRowNo(json);
                    rsl.Result = true;
                    log.Info("PurchaseInPrint程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPrintedBarcodes_ByRdrecord01_cCode_iRowNo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        /// <summary>
        /// 原辅料重新打码 自动提示
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult MatAuxRePrint_AutoSuggest()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("MatAuxRePrint_AutoSuggest参数：" + json);
                    rsl.Data = barBLL.MatAuxRePrint_AutoSuggest(json);
                    rsl.Result = true;
                    log.Info("MatAuxRePrint_AutoSuggest程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("MatAuxRePrint_AutoSuggest：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        /// <summary>
        /// 版辊打码自动提示
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult PlateRoller_AutoSuggest()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("PlateRoller_AutoSuggest参数：" + json);
                    rsl.Data = barBLL.PlateRoller_AutoSuggest(json);
                    rsl.Result = true;
                    log.Info("PlateRoller_AutoSuggest程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("PlateRoller_AutoSuggest：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }

        /// <summary>
        /// 原辅料重新打码 获取旧条码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetOldBarCodeInfo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetOldBarCodeInfo：" + json);
                    rsl.Data = barBLL.GetOldBarCodeInfo(json);
                    rsl.Result = true;
                    log.Info("GetOldBarCodeInfo程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetOldBarCodeInfo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 原辅料重新打码 打印方法
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult MatAuxRePrint()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("MatAuxRePrint：" + json);
                    rsl = barBLL.MatAuxRePrint(json);

                    log.Info("MatAuxRePrint程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("MatAuxRePrint：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetWarehouseList()
        {
            rsl = new ReturnResult();
            try
            {
                WareHouseBLL wareBLL = new WareHouseBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetWarehouseList：" + json);
                    rsl.Data = JsonConvert.SerializeObject(wareBLL.GetWarehouseList(json));
                    rsl.Result = true;
                    log.Info("GetWarehouseList程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetWarehouseList：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }
        [HttpPost]
        public JsonResult CheckPlanGongXu()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var jsonStr = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("CheckPlanGongXu参数：" + jsonStr);
                    var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                    rsl = barBLL.isCheckGx(json["plCode"].ToString(),json["gxCode"].ToString());
                    log.Info("CheckPlanGongXu程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("CheckPlanGongXu方法异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetMachineList()
        {
            rsl = new ReturnResult();
            try
            {
                WareHouseBLL wareBLL = new WareHouseBLL();
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetMachineList：" + json);
                    rsl.Data = JsonConvert.SerializeObject(wareBLL.GetMachineList(json));
                    rsl.Result = true;
                    log.Info("GetMachineList程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetWarehouseList：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }
        /// <summary>
        /// 获取存货列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetProductList()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetProductList：" + json);
                    rsl.Data = JsonConvert.SerializeObject(barBLL.GetProductList(json));
                    rsl.Result = true;
                    log.Info("GetProductList程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetProductList：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        [HttpPost]
        public JsonResult GetPlateRollerInfo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetPlateRollerInfo：参数" + json);
                    rsl = barBLL.GetPlateRollerInfo(json);
                    log.Info("GetPlateRollerInfo程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPlateRollerInfo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        [HttpPost]
        public JsonResult GongXuMachine()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    BasicBLL basicBLL = new BasicBLL();
                    log.Info("GongXuMachine：参数" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    string gxCode = "NN";
                    if (obj.Property("gxCode") != null && !string.IsNullOrWhiteSpace(obj["gxCode"].ToString()))
                    {
                        gxCode = obj["gxCode"].ToString();
                    }
                    rsl = basicBLL.GetGongXuMachine(gxCode);
                    log.Info("GongXuMachine程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GongXuMachine：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }



        /// <summary>
        /// 下载最新客户端文件
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetLastPrintClient()
        {
            string webRootPath = _webHostEnvironment.WebRootPath;
            var updatePath = Path.Combine(webRootPath, "UpdateFiles");

            log.Info("获取更新文件地址：" + updatePath);

            // 获取修改时间最新的文件
            var di = new DirectoryInfo(updatePath);
            var files = di.GetFileSystemInfos();
            var orderedFiles = files.Where(f => f.Name.EndsWith(".exe"))
                .OrderBy(f => f.LastWriteTime).ToList();
            var fileName = orderedFiles[0].FullName;

            var memory = new MemoryStream();
            using (var stream = new FileStream(fileName, FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;

            return File(memory, GetContentType(fileName), "BarCode-Project.exe");
        }
        private string GetContentType(string path)
        {
            var provider = new FileExtensionContentTypeProvider();
            string contentType;
            if (!provider.TryGetContentType(path, out contentType))
            {
                contentType = "application/octet-stream";
            }
            return contentType;
        }
        [HttpPost]
        public JsonResult GetRelativeBarCodes()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetRelativeBarCodes：" + json);
                    rsl.Data = barBLL.GetRelativeBarCodes(json);
                    rsl.Result = true;
                    log.Info("GetRelativeBarCodes程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetRelativeBarCodes：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        [HttpPost]
        public JsonResult SaveBanJia()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;
                BasicBLL basicBLL = new BasicBLL();
                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("SaveBanJia：" + json);
                    rsl.Data = basicBLL.SaveBanJia(json);
                    rsl.Result = true;
                    log.Info("SaveBanJia程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("SaveBanJia：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }


        [HttpPost]
        public JsonResult GetReBarInfo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetReBarInfo：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = barBLL.GetBarCodeInfoByCode(obj["barCode"].ToString());
                    log.Info("GetReBarInfo程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetReBarInfo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        [HttpPost]
        public JsonResult GetScannedBarCodeInfo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetRelativeBarCodes：" + json);
                    rsl.Data = barBLL.GetScannedBarCodeInfo(json);
                    rsl.Result = true;
                    log.Info("GetScannedBarCodeInfo程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetScannedBarCodeInfo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 判断是否为最后一道工序
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult IsFinalStep()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("IsFinalStep：" + json);
                    //rsl.Data = barBLL.GetScannedBarCodeInfo(json);
                    rsl.Data = barBLL.IsFinalStep(json);
                    rsl.Result = true;
                    log.Info("IsFinalStep程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("IsFinalStep：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 获取执行标准
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getZhxbz()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("getZhxbz：" + json);
                    //rsl.Data = barBLL.GetScannedBarCodeInfo(json);
                    rsl.Data = barBLL.getZhxbz(json);
                    rsl.Result = true;
                    log.Info("getZhxbz程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("getZhxbz：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }
        /// <summary>
        /// 获取材质
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult getCuCaiZhi()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("getCuCaiZhi：" + json);
                    //rsl.Data = barBLL.GetScannedBarCodeInfo(json);
                    rsl.Data = barBLL.getCuCaiZhi(json);
                    rsl.Result = true;
                    log.Info("getCuCaiZhi程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("getCuCaiZhi：异常" + ex.Message);
                rsl.Message = ex.Message;
            }
            return Json(rsl);
        }


        //获取条码信息（分切时，材质等信息与关联条码的一致）
        [HttpPost]
        public JsonResult getRelationBarInfo()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("getRelationBarInfo：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    rsl = barBLL.getRelationBarInfo(obj["barCode"].ToString());
                    log.Info("getRelationBarInfo程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("getRelationBarInfo：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);
        }

        [HttpPost]
        public JsonResult GetPlanTechnologyForm()
        {
            rsl = new ReturnResult();
            try
            {
                Stream reqStream = Request.Body;
                StreamReader streamReader = new StreamReader(reqStream);
                var json = streamReader.ReadToEndAsync().Result;

                if (string.IsNullOrWhiteSpace(json))
                {
                    rsl.Message = "无法获取传递参数"; return Json(rsl);
                }
                else
                {
                    log.Info("GetPlanTechnologyForm：" + json);
                    var obj = JsonConvert.DeserializeObject<JObject>(json);
                    PlanBLL planBLL = new PlanBLL();
                    rsl = planBLL.GetPlanTechnologyFormToPrint(obj["plCode"].ToString(), obj["gxCode"].ToString());
                    log.Info("GetPlanTechnologyForm程序执行结果：" + JsonConvert.SerializeObject(rsl));
                }
            }
            catch (Exception ex)
            {
                log.Error("GetPlanTechnologyForm：异常" + ex.Message);
                rsl.Message = ex.Message;
            }

            return Json(rsl);

        }


    }
}
